package com.hospital.BaseActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.hospital.activity.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wangjun on 2015/6/19.
 */
public class CharDemoActivity extends  BaseActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.char_demo_list);
        ArrayList<String> objects = new ArrayList<String>();
        objects.add("线性图表");
        objects.add("饼状图表");
        objects.add("柱状图1");
        objects.add("柱状图2");
        MyAdapter adapter = new MyAdapter(this, objects);

        ListView lv = (ListView) findViewById(R.id.listView1);
        lv.setAdapter(adapter);

        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent;

                switch (i) {
                    case 0:
                        intent = new Intent(CharDemoActivity.this, LineChartActivity1.class);
                        startActivity(intent);
                        break;
//                    case 1:
//                        intent = new Intent(this, LineChartActivity2.class);
//                        startActivity(intent);
//                        break;
//                    case 2:
//                        intent = new Intent(this, BarChartActivity.class);
//                        startActivity(intent);
//                        break;
//                    case 3:
//                        intent = new Intent(this, HorizontalBarChartActivity.class);
//                        startActivity(intent);
//                        break;
//                    case 4:
//                        intent = new Intent(this, CombinedChartActivity.class);
//                        startActivity(intent);
//                        break;

                }

            }
        });


    }


    private class MyAdapter extends ArrayAdapter<String> {

        public MyAdapter(Context context, List<String> objects) {
            super(context, 0, objects);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            String c = getItem(position);

            ViewHolder holder = null;

            if (convertView == null) {

                holder = new ViewHolder();

                convertView = LayoutInflater.from(getContext()).inflate(R.layout.char_demo_list, null);
                holder.tvName = (TextView) convertView.findViewById(R.id.tvName);
          //      holder.tvDesc = (TextView) convertView.findViewById(R.id.tvDesc);

                convertView.setTag(holder);

            } else {
                holder = (ViewHolder) convertView.getTag();
            }

            holder.tvName.setText(c);
          //  holder.tvDesc.setText(c.desc);

            return convertView;
        }

        private class ViewHolder {

            TextView tvName;
        }
    }
}
